<template>
<div class="register">
  <el-form ref="form" :model="form" label-width="80px">
    <h2 style="text-align: center">住户注册</h2>
    <el-form-item label="住户名字">
      <el-input v-model="form.householdName"></el-input>
    </el-form-item>
    <el-form-item label="性别">
      <template>
        <el-radio v-model="form.sex" label="1">男</el-radio>
        <el-radio v-model="form.sex" label="0">女</el-radio>
      </template>
    </el-form-item>
    <el-form-item label="电话">
      <el-input v-model="form.phone"></el-input>
    </el-form-item>
    <el-form-item label="小区">
      <el-select v-model="form.communityName" placeholder="请选择小区">
        <el-option  v-for="item in communityList"
                    :label=item.communityName
                    :value=item.communityName
                    ></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="楼栋">
      <el-select v-model="form.buildingName" placeholder="请选择楼栋">
        <el-option
          v-for="item in buildingList"
          :label=item.buildingName
          :value=item.buildingName
        />
      </el-select>
    </el-form-item>
    <el-form-item label="地址">
      <el-input v-model="form.address"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">立即注册</el-button>
      <el-button>取消</el-button>
    </el-form-item>
  </el-form>
</div>
</template>

<script>
import {selectAllCommunity} from "@/api/basicsys/community";
import {registeraddHousehold} from "@/api/basicsys/household";
import {registeraddUser} from "@/api/basicsys/user";
import {listBuilding, selectAllBuilding} from "@/api/basicsys/building";
import building from "./basicsys/building/index.vue";
import {registerAddlogin} from "@/api/system/user";

export default {
  computed: {
    building() {
      return building
    }
  },
  data() {
    return {
      form: {
        //id
        id:null,
        //住户名字
        householdName: '',
        //性别
        sex:"",
        //电话
        phone:"",
        //微信
        wechat:"",
        // 密码
        password:"",
        //小区名字
        communityName:null,
        // 楼栋名字
        buildingName:null,
        //地址
        address:"",
      },
      //查询小区
      communityList:[],
      //查询楼栋
      buildingList:[]
    }
  },
  methods: {
    /** 查询楼栋管理列表 */
    getBuildingList() {
      this.loading = true;
      selectAllBuilding().then(response => {
        console.log(response)
        this.buildingList=response;
      });
    },
    /*查询所有的小区名字*/
    getCommunityList() {
      this.loading = true;
      selectAllCommunity().then(response => {
        console.log(response)
        this.communityList=response;
      });
    },
    onSubmit() {
      registeraddHousehold(this.form).then(response =>{
        console.log("请求发送成功")
      });
      registeraddUser(this.form).then(reponse=>{
        console.log("请求发送成功")
      });
      registerAddlogin(this.form).then(reponse=>{
        console.log("添加登录用户成功")
      })

    }
  },
  mounted() {
    this.getBuildingList();
    this.getCommunityList();
  }
}
</script>
<style rel="stylesheet/scss" lang="scss">
.register{
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  background-size: cover;
}
</style>
